﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using YArchitech.Controls;
using YArchitech.LIB;
using YArchitech.Revit;

namespace YArchitech.DataModel
{
	public class SpaceFamilyDataReader
	{
		public SpaceFamilyDataReader()
		{
			this.sqlHelper = new SQLiteDataBaseHelper(Path.Combine(@"C:\Hongye\HYRME2018\Data", "HYBIMSPACE.db3"));
		}

		public TreeView GetAllNameAndImage2DByCategory(string typeName, int type = 0)
		{
			TreeView treeView = new TreeView();
			foreach (object obj in this.sqlHelper.GetAllNameAndImage2DByCategory(typeName, type).Rows)
			{
				DataRow dataRow = (DataRow)obj;
				TreeNode treeNode = new TreeNode(dataRow["Name"].ToString());
				treeNode.Tag = new ListItem(dataRow["Name"].ToString(), Path.Combine(Product.FamilyImageLocation, typeName, dataRow["Image"].ToString()), dataRow["Id"]);
				treeView.Nodes.Add(treeNode);
			}
			return treeView;
		}

		public string GetFamilyFullPath(int id, string typeName, string SymbolName, Document doc, BuiltInCategory builtInCate)
		{
			DataTable infoById = this.sqlHelper.GetInfoById(typeName, id);
			if (infoById == null || infoById.Rows.Count < 1)
			{
				return null;
			}
			string path = infoById.Rows[0]["Family"].ToString();
			return Path.Combine(Product.FamilyLocation, RevitVersion.GetVersionNumber(doc), typeName, path);
		}

		public List<EquipmentCoilParameter> GetAllEquipmentCoilInfo(Document doc)
		{
			List<EquipmentCoilParameter> list = new List<EquipmentCoilParameter>();
			foreach (object obj in this.sqlHelper.GetTableSchema("EquipmentCoil").Rows)
			{
				DataRow dataRow = (DataRow)obj;
				if (dataRow != null)
				{
					list.Add(new EquipmentCoilParameter(dataRow["id"].ToString(), dataRow["Name"].ToString(), dataRow["AirFlow"].ToString(), dataRow["CoolFlow"].ToString(), dataRow["HotFlow"].ToString(), dataRow["StructureType"].ToString(), dataRow["InstallType"].ToString(), dataRow["ConnectType"].ToString(), dataRow["Family"].ToString(), dataRow["Factory"].ToString())
					{
						FamilyId = dataRow["id"].ToString(),
						Image = Path.Combine(Product.FamilyImageLocation, "EquipmentCoil", dataRow["Image"].ToString()),
						Family = Path.Combine(Product.FamilyLocation, RevitVersion.GetVersionNumber(doc), "EquipmentCoil", dataRow["Family"].ToString())
					});
				}
			}
			return list;
		}

		public DataTable GetWares()
		{
			return this.sqlHelper.GetTableSchema("EquipmentSanitary");
		}

		public DataTable GetFurniture()
		{
			DataTable result;
			try
			{
				result = this.sqlHelper.GetTableSchema("EquipmentFurniture");
			}
			catch
			{
				YJKMessageBox.Show("数据库出错");
				result = null;
			}
			return result;
		}

		public List<ListItem> GetAllNameAndImage(string typeName)
		{
			List<ListItem> list = new List<ListItem>();
			foreach (object obj in this.sqlHelper.GetAllName(typeName).Rows)
			{
				DataRow dataRow = (DataRow)obj;
				list.Add(new ListItem(dataRow["Name"].ToString(), Path.Combine(Product.FamilyImageLocation, typeName, dataRow["Image"].ToString()), dataRow["Id"].ToString()));
			}
			return list;
		}

		public List<FireExtinguisherClass> GetFireExtinguisherData(string typeName, string style)
		{
			List<FireExtinguisherClass> list = new List<FireExtinguisherClass>();
			foreach (object obj in this.sqlHelper.GetTableSchema(typeName).Rows)
			{
				DataRow dataRow = (DataRow)obj;
				if (dataRow["Style"].ToString() == style.ToString())
				{
					list.Add(new FireExtinguisherClass(dataRow["Style"].ToString(), dataRow["Agent"].ToString(), dataRow["Level-A"].ToString(), dataRow["Level-B"].ToString(), dataRow["Model"].ToString()));
				}
			}
			return list;
		}

		public List<ListItem> GetAllNameAndImage(string typeName, int type)
		{
			List<ListItem> list = new List<ListItem>();
			foreach (object obj in this.sqlHelper.GetAllNameAndCategory(typeName).Rows)
			{
				DataRow dataRow = (DataRow)obj;
				if (dataRow["Category"].ToString() == type.ToString())
				{
					list.Add(new ListItem(dataRow["Name"].ToString(), Path.Combine(Product.FamilyImageLocation, typeName, dataRow["Image"].ToString()), dataRow["Id"].ToString()));
				}
			}
			return list;
		}

		public List<ListItem> GetAllName(string typeName)
		{
			List<ListItem> list = new List<ListItem>();
			DataTable allName = this.sqlHelper.GetAllName(typeName);
			int num = 1;
			foreach (object obj in allName.Rows)
			{
				DataRow dataRow = (DataRow)obj;
				list.Add(new ListItem(dataRow["Name"].ToString(), num.ToString(), dataRow["Id"].ToString()));
				num++;
			}
			return list;
		}

		public List<ListItem> GetAllName(string typeName, int nCategory)
		{
			List<ListItem> list = new List<ListItem>();
			DataTable allNameAndCategory = this.sqlHelper.GetAllNameAndCategory(typeName);
			int num = 1;
			foreach (object obj in allNameAndCategory.Rows)
			{
				DataRow dataRow = (DataRow)obj;
				if (nCategory == Convert.ToInt32(dataRow["Category"].ToString()))
				{
					list.Add(new ListItem(dataRow["Name"].ToString(), num.ToString(), dataRow["Id"].ToString()));
				}
				num++;
			}
			return list;
		}

		public List<ListItem> GetInfoById(string typeName, int id)
		{
			List<ListItem> list = new List<ListItem>();
			DataTable infoById = this.sqlHelper.GetInfoById(typeName, id);
			if (infoById != null && infoById.Rows.Count > 0)
			{
				foreach (object obj in infoById.Columns)
				{
					DataColumn dataColumn = (DataColumn)obj;
					string value = infoById.Rows[0][dataColumn.ColumnName].ToString();
					if (dataColumn.ColumnName == "Family")
					{
						value = Path.Combine(Product.FamilyLocation, RevitVersion.Version, typeName, infoById.Rows[0][dataColumn.ColumnName].ToString());
					}
					else if (dataColumn.ColumnName == "Image" || dataColumn.ColumnName == "Image2D")
					{
						value = Path.Combine(Product.FamilyImageLocation, typeName, infoById.Rows[0][dataColumn.ColumnName].ToString());
					}
					list.Add(new ListItem(dataColumn.ColumnName, value, dataColumn.DataType));
				}
			}
			return list;
		}

		public List<ListItem> GetInfoById(int id)
		{
			List<ListItem> list = new List<ListItem>();
			DataTable tableSchema = this.sqlHelper.GetTableSchema("EquipmentCoil");
			if (tableSchema == null || tableSchema.Rows.Count < 1)
			{
				return list;
			}
			foreach (object obj in tableSchema.Rows)
			{
				DataRow dataRow = (DataRow)obj;
				if (dataRow != null && dataRow["id"].ToString() == id.ToString())
				{
					IEnumerator enumerator2 = tableSchema.Columns.GetEnumerator();
					{
						while (enumerator2.MoveNext())
						{
							object obj2 = enumerator2.Current;
							DataColumn dataColumn = (DataColumn)obj2;
							string value = tableSchema.Rows[tableSchema.Rows.IndexOf(dataRow)][dataColumn.ColumnName].ToString();
							if (dataColumn.ColumnName == "Family")
							{
								value = Path.Combine(Product.FamilyLocation, RevitVersion.Version, "EquipmentCoil", tableSchema.Rows[0][dataColumn.ColumnName].ToString());
							}
							else if (dataColumn.ColumnName == "Image" || dataColumn.ColumnName == "Image2D")
							{
								value = Path.Combine(Product.FamilyImageLocation, "EquipmentCoil-All", tableSchema.Rows[0][dataColumn.ColumnName].ToString());
							}
							list.Add(new ListItem(dataColumn.ColumnName, value, dataColumn.DataType));
						}
						break;
					}
				}
			}
			return list;
		}

		public List<ListItem> GetInfoById(string typeName, int id, Document doc)
		{
			List<ListItem> list = new List<ListItem>();
			if (doc == null)
			{
				return list;
			}
			DataTable infoById = this.sqlHelper.GetInfoById(typeName, id);
			if (infoById != null && infoById.Rows.Count > 0)
			{
				foreach (object obj in infoById.Columns)
				{
					DataColumn dataColumn = (DataColumn)obj;
					string value = infoById.Rows[0][dataColumn.ColumnName].ToString();
					if (dataColumn.ColumnName == "Family")
					{
						value = Path.Combine(Product.FamilyLocation, RevitVersion.GetVersionNumber(doc), typeName, infoById.Rows[0][dataColumn.ColumnName].ToString());
					}
					else if (dataColumn.ColumnName == "Image" || dataColumn.ColumnName == "Image2D")
					{
						value = Path.Combine(Product.FamilyImageLocation, typeName, infoById.Rows[0][dataColumn.ColumnName].ToString());
					}
					list.Add(new ListItem(dataColumn.ColumnName, value, dataColumn.DataType));
				}
			}
			return list;
		}

		public bool SetInfoById(string typeName, int id, List<ListItem> infos)
		{
			string text = "";
			DataTable infoById = this.sqlHelper.GetInfoById(typeName, id);
			if (infoById != null && infoById.Rows.Count > 0)
			{
				foreach (object obj in infoById.Columns)
				{
					DataColumn dataColumn = (DataColumn)obj;
					foreach (ListItem listItem in infos)
					{
						infoById.Rows[0][dataColumn.ColumnName].ToString();
						if (dataColumn.ColumnName.ToUpper() != "ID" && dataColumn.ColumnName.ToUpper().Equals(listItem.Name.ToUpper()) && !string.IsNullOrEmpty(listItem.Value))
						{
							if (dataColumn.DataType.Equals(typeof(string)))
							{
								text = string.Concat(new string[]
								{
									text,
									dataColumn.ColumnName,
									"='",
									listItem.Value,
									"',"
								});
								break;
							}
							text = string.Concat(new string[]
							{
								text,
								dataColumn.ColumnName,
								"=",
								listItem.Value,
								","
							});
							break;
						}
					}
				}
			}
			if (!string.IsNullOrEmpty(text))
			{
				text = text.Substring(0, text.Length - 1);
			}
			return this.sqlHelper.SetInfoById(typeName, id, text);
		}

		public bool SetInfoById(int id, List<ListItem> infos)
		{
			string text = "";
			DataTable tableSchema = this.sqlHelper.GetTableSchema("EquipmentCoil");
			if (tableSchema == null || tableSchema.Rows.Count < 1)
			{
				return false;
			}
			DataRow dataRow = null;
			foreach (object obj in tableSchema.Rows)
			{
				DataRow dataRow2 = (DataRow)obj;
				if (dataRow2 != null && dataRow2["id"].ToString() == id.ToString())
				{
					dataRow = dataRow2;
					break;
				}
			}
			if (dataRow == null)
			{
				return false;
			}
			if (tableSchema != null && tableSchema.Rows.Count > 0)
			{
				foreach (object obj2 in tableSchema.Columns)
				{
					DataColumn dataColumn = (DataColumn)obj2;
					foreach (ListItem listItem in infos)
					{
						tableSchema.Rows[0][dataColumn.ColumnName].ToString();
						if (dataColumn.ColumnName.ToUpper() != "ID" && dataColumn.ColumnName.ToUpper().Equals(listItem.Name.ToUpper()) && !string.IsNullOrEmpty(listItem.Value))
						{
							if (dataColumn.DataType.Equals(typeof(string)))
							{
								text = string.Concat(new string[]
								{
									text,
									dataColumn.ColumnName,
									"='",
									listItem.Value,
									"',"
								});
								break;
							}
							text = string.Concat(new string[]
							{
								text,
								dataColumn.ColumnName,
								"=",
								listItem.Value,
								","
							});
							break;
						}
					}
				}
			}
			if (!string.IsNullOrEmpty(text))
			{
				text = text.Substring(0, text.Length - 1);
			}
			return this.sqlHelper.SetInfoById("EquipmentCoil", id, text);
		}

		public FamilySymbol GetFamilySymbolByNameSubTran(string name, string typeName, Document doc, BuiltInCategory builtInCategory)
		{
			FamilySymbol result = null;
			DataTable infoByName = this.sqlHelper.GetInfoByName(typeName, name);
			if (infoByName == null || infoByName.Rows.Count < 1)
			{
				return result;
			}
			string text = infoByName.Rows[0]["Family"].ToString();
			string text2 = Path.Combine(Product.FamilyLocation, RevitVersion.GetVersionNumber(doc), typeName, text);
			Family family = null;
			SubTransaction subTransaction = null;
			try
			{
				foreach (Element element in YJKElementFilter.GetElementByCategory(doc, typeof(FamilySymbol), builtInCategory))
				{
					if (element is FamilySymbol && (element as FamilySymbol).Family.Name == text.Substring(0, text.IndexOf(".")))
					{
						result = (element as FamilySymbol);
						return result;
					}
				}
				subTransaction = new SubTransaction(doc);
				subTransaction.Start();
				doc.LoadFamily(text2, out family);
				subTransaction.Commit();
			}
			catch (Exception)
			{
			}
			finally
			{
                if (subTransaction != null && subTransaction.GetStatus() != TransactionStatus.Committed)
				{
					subTransaction.RollBack();
				}
			}
			if (family != null)
			{
				using (List<FamilySymbol>.Enumerator enumerator2 = family.GetSymbols().GetEnumerator())
				{
					if (enumerator2.MoveNext())
					{
						result = enumerator2.Current;
					}
				}
			}
			return result;
		}

		public FamilySymbol GetFamilySymbolById(int id, string typeName, Document doc, BuiltInCategory builtInCategory)
		{
			FamilySymbol result = null;
			DataTable infoById = this.sqlHelper.GetInfoById(typeName, id);
			if (infoById == null || infoById.Rows.Count < 1)
			{
				return result;
			}
			string text = infoById.Rows[0]["Family"].ToString();
			string text2 = Path.Combine(Product.FamilyLocation, RevitVersion.GetVersionNumber(doc), typeName, text);
			Family family = null;
			Transaction transaction = null;
			try
			{
				foreach (Element element in YJKElementFilter.GetElementByCategory(doc, typeof(FamilySymbol), builtInCategory))
				{
					if ((element as FamilySymbol).Family.Name == text.Substring(0, text.IndexOf(".")))
					{
						FamilySymbol result2;
						result = (result2 = (element as FamilySymbol));
						return result2;
					}
				}
				transaction = new Transaction(doc, "加载族");
				transaction.Start();
				if (!string.IsNullOrEmpty(text2))
				{
					doc.LoadFamily(text2, out family);
					transaction.Commit();
				}
			}
			catch (Exception ex)
			{
				ex.ToString();
			}
			finally
			{
				if (transaction != null && transaction.GetStatus() != TransactionStatus.Committed)
				{
					transaction.RollBack();
				}
			}
			if (family != null)
			{
				using (List<FamilySymbol>.Enumerator enumerator2 = family.GetSymbols().GetEnumerator())
				{
					if (enumerator2.MoveNext())
					{
						result = enumerator2.Current;
					}
				}
			}
			return result;
		}

		public FamilySymbol GetFamilySymbolById(int id, Document doc, BuiltInCategory builtInCategory)
		{
			FamilySymbol result = null;
			DataTable tableSchema = this.sqlHelper.GetTableSchema("EquipmentCoil");
			if (tableSchema == null || tableSchema.Rows.Count < 1)
			{
				return result;
			}
			DataRow dataRow = null;
			foreach (object obj in tableSchema.Rows)
			{
				DataRow dataRow2 = (DataRow)obj;
				if (dataRow2 != null && dataRow2["id"].ToString() == id.ToString())
				{
					dataRow = dataRow2;
					break;
				}
			}
			if (dataRow == null)
			{
				return result;
			}
			string text = dataRow["Family"].ToString();
			string text2 = Path.Combine(Product.FamilyLocation, RevitVersion.GetVersionNumber(doc), "EquipmentCoil", text);
			Family family = null;
			Transaction transaction = null;
			try
			{
				foreach (Element element in YJKElementFilter.GetElementByCategory(doc, typeof(FamilySymbol), builtInCategory))
				{
					if ((element as FamilySymbol).Family.Name == text.Substring(0, text.IndexOf(".")))
					{
						FamilySymbol result2;
						result = (result2 = (element as FamilySymbol));
						return result2;
					}
				}
				transaction = new Transaction(doc, "加载族");
				transaction.Start();
				doc.LoadFamily(text2, out family);
				transaction.Commit();
			}
			catch (Exception)
			{
			}
			finally
			{
				if (transaction != null && transaction.GetStatus() != TransactionStatus.Committed)
				{
					transaction.RollBack();
				}
			}
			if (family != null)
			{
				using (List<FamilySymbol>.Enumerator enumerator3 = family.GetSymbols().GetEnumerator())
				{
					if (enumerator3.MoveNext())
					{
						result = enumerator3.Current;
					}
				}
			}
			return result;
		}

		public FamilySymbol GetFamilySymbolByIdSubTran(int id, string typeName, Document doc, BuiltInCategory builtInCategory)
		{
			FamilySymbol result = null;
			DataTable infoById = this.sqlHelper.GetInfoById(typeName, id);
			if (infoById == null || infoById.Rows.Count < 1)
			{
				return result;
			}
			string text = infoById.Rows[0]["Family"].ToString();
			string text2 = Path.Combine(Product.FamilyLocation, RevitVersion.GetVersionNumber(doc), typeName, text);
			Family family = null;
			SubTransaction subTransaction = null;
			try
			{
				foreach (Element element in YJKElementFilter.GetElementByCategory(doc, typeof(FamilySymbol), builtInCategory))
				{
					if ((element as FamilySymbol).Family.Name == text.Substring(0, text.IndexOf(".")))
					{
						FamilySymbol result2;
						result = (result2 = (element as FamilySymbol));
						return result2;
					}
				}
				subTransaction = new SubTransaction(doc);
				subTransaction.Start();
				doc.LoadFamily(text2, out family);
				subTransaction.Commit();
			}
			catch (Exception)
			{
			}
			finally
			{
                if (subTransaction != null && subTransaction.GetStatus() != TransactionStatus.Committed)
				{
					subTransaction.RollBack();
				}
			}
			if (family != null)
			{
				using (List<FamilySymbol>.Enumerator enumerator2 = family.GetSymbols().GetEnumerator())
				{
					if (enumerator2.MoveNext())
					{
						result = enumerator2.Current;
					}
				}
			}
			return result;
		}

		public FamilySymbol GetFamilySymbolById(int id, string typeName, string SymbolName, Document doc, BuiltInCategory builtInCate)
		{
			FamilySymbol familySymbol = null;
			DataTable infoById = this.sqlHelper.GetInfoById(typeName, id);
			if (infoById == null || infoById.Rows.Count < 1)
			{
				return familySymbol;
			}
			string text = infoById.Rows[0]["Family"].ToString();
			string text2 = Path.Combine(Product.FamilyLocation, RevitVersion.GetVersionNumber(doc), typeName, text);
			Family family = null;
			bool flag = false;
			Transaction transaction = null;
			try
			{
				foreach (Element element in YJKElementFilter.GetElementByCategory(doc, typeof(FamilySymbol), builtInCate))
				{
					if ((element as FamilySymbol).Family.Name == text.Substring(0, text.IndexOf(".")))
					{
						flag = true;
						familySymbol = (element as FamilySymbol);
						if (string.IsNullOrEmpty(SymbolName) || familySymbol.Name == SymbolName)
						{
							return familySymbol;
						}
					}
				}
				if (flag)
				{
					return familySymbol;
				}
				transaction = new Transaction(doc, "载入族");
				transaction.Start();
				doc.LoadFamily(text2, out family);
				transaction.Commit();
			}
			catch (Exception)
			{
			}
			finally
			{
				if (transaction != null && transaction.GetStatus() != TransactionStatus.Committed)
				{
					transaction.RollBack();
				}
			}
			if (family != null)
			{
				using (List<FamilySymbol>.Enumerator enumerator2 = family.GetSymbols().GetEnumerator())
				{
					while (enumerator2.MoveNext())
					{
						familySymbol = enumerator2.Current;
						if (string.IsNullOrEmpty(SymbolName))
						{
							break;
						}
						if (familySymbol.Name == SymbolName)
						{
							break;
						}
					}
				}
			}
			return familySymbol;
		}

		public FamilySymbol GetFamilySymbolByIdSubTran(int id, string typeName, string SymbolName, Document doc, BuiltInCategory builtInCate)
		{
			FamilySymbol familySymbol = null;
			DataTable infoById = this.sqlHelper.GetInfoById(typeName, id);
			if (infoById == null || infoById.Rows.Count < 1)
			{
				return familySymbol;
			}
			string text = infoById.Rows[0]["Family"].ToString();
			string text2 = Path.Combine(Product.FamilyLocation, RevitVersion.GetVersionNumber(doc), typeName, text);
			Family family = null;
			bool flag = false;
			SubTransaction subTransaction = null;
			try
			{
				foreach (Element element in YJKElementFilter.GetElementByCategory(doc, typeof(FamilySymbol), builtInCate))
				{
					if ((element as FamilySymbol).Family.Name == text.Substring(0, text.IndexOf(".")))
					{
						flag = true;
						familySymbol = (element as FamilySymbol);
						if (string.IsNullOrEmpty(SymbolName) || familySymbol.Name == SymbolName)
						{
							return familySymbol;
						}
					}
				}
				if (flag)
				{
					return familySymbol;
				}
				subTransaction = new SubTransaction(doc);
				subTransaction.Start();
				doc.LoadFamily(text2, out family);
				subTransaction.Commit();
			}
			catch (Exception)
			{
			}
			finally
			{
                if (subTransaction != null && subTransaction.GetStatus() != TransactionStatus.Committed)
				{
					subTransaction.RollBack();
				}
			}
			if (family != null)
			{
				using (List<FamilySymbol>.Enumerator enumerator2 = family.GetSymbols().GetEnumerator())
				{
					while (enumerator2.MoveNext())
					{
						familySymbol = enumerator2.Current;
						if (string.IsNullOrEmpty(SymbolName))
						{
							break;
						}
						if (familySymbol.Name == SymbolName)
						{
							break;
						}
					}
				}
			}
			return familySymbol;
		}

		private FamilyInstance GetFamilyById(int id, string typeName, Document doc)
		{
			FamilyInstance result = null;
			FamilySymbol familySymbol = null;
			DataTable infoById = this.sqlHelper.GetInfoById(typeName, id);
			if (infoById == null || infoById.Rows.Count < 1)
			{
				return result;
			}
			string text = Path.Combine(Product.FamilyLocation, RevitVersion.GetVersionNumber(doc), typeName, infoById.Rows[0]["Family"].ToString());
			Family family = null;
			if (doc.LoadFamily(text, out family))
			{
				using (List<FamilySymbol>.Enumerator enumerator = family.GetSymbols().GetEnumerator())
				{
					if (enumerator.MoveNext())
					{
						familySymbol = enumerator.Current;
					}
				}
			}
			if (familySymbol != null)
			{
				UnifiedModified.ActivateFamilySymbol(familySymbol);
				result = doc.Create.NewFamilyInstance(new XYZ(0.0, 0.0, 0.0), familySymbol, 0);
			}
			return result;
		}

		public string GetFamilyNameById(int id, string typeName)
		{
			string result = "";
			DataTable infoById = this.sqlHelper.GetInfoById(typeName, id);
			if (infoById != null && infoById.Rows.Count > 0)
			{
				result = infoById.Rows[0]["family"].ToString();
			}
			return result;
		}

		public string GetFamilyPathById(int id, string typeName, Document doc)
		{
			string result = "";
			DataTable infoById = this.sqlHelper.GetInfoById(typeName, id);
			if (infoById != null && infoById.Rows.Count > 0)
			{
				result = Path.Combine(Product.FamilyLocation, RevitVersion.GetVersionNumber(doc), typeName, infoById.Rows[0]["family"].ToString());
			}
			return result;
		}

		public List<ListItemWaterTank> GetAllWaterTank(string tableName)
		{
			List<ListItemWaterTank> list = new List<ListItemWaterTank>();
			DataTable tableSchema = this.sqlHelper.GetTableSchema(tableName);
			if (tableSchema != null && tableSchema.Rows.Count > 0)
			{
				foreach (object obj in tableSchema.Rows)
				{
					DataRow dataRow = (DataRow)obj;
					string image = Path.Combine(Product.FamilyImageLocation, tableName, dataRow["Image"].ToString());
					list.Add(new ListItemWaterTank(dataRow["Id"].ToString(), dataRow["Name"].ToString(), dataRow["Family"].ToString(), image));
				}
			}
			return list;
		}

		public List<ListItemWaterTankPara> GetWaterTankParaById(string id, string tablename)
		{
			List<ListItemWaterTankPara> list = new List<ListItemWaterTankPara>();
			DataTable tableSchema = this.sqlHelper.GetTableSchema(tablename);
			if (tableSchema != null && tableSchema.Rows.Count > 0)
			{
				foreach (object obj in tableSchema.Rows)
				{
					DataRow dataRow = (DataRow)obj;
					if (id == dataRow["Id"].ToString())
					{
						list.Add(new ListItemWaterTankPara(dataRow["Id"].ToString(), dataRow["SPECName"].ToString(), dataRow["Volume"].ToString(), dataRow["Height"].ToString(), dataRow["Width"].ToString(), dataRow["Length"].ToString(), dataRow["PipeIn"].ToString(), dataRow["PipeOut"].ToString(), dataRow["PipeOverFlow"].ToString(), dataRow["PipeBlowOff"].ToString(), dataRow["Weight"].ToString()));
					}
				}
			}
			return list;
		}

		public List<ListItemWaterTankPara> GetWaterTankParaOfAll(string tablename)
		{
			List<ListItemWaterTankPara> list = new List<ListItemWaterTankPara>();
			DataTable tableSchema = this.sqlHelper.GetTableSchema(tablename);
			if (tableSchema != null && tableSchema.Rows.Count > 0)
			{
				foreach (object obj in tableSchema.Rows)
				{
					DataRow dataRow = (DataRow)obj;
					list.Add(new ListItemWaterTankPara(dataRow["Id"].ToString(), dataRow["SPECName"].ToString(), dataRow["Volume"].ToString(), dataRow["Height"].ToString(), dataRow["Width"].ToString(), dataRow["Length"].ToString(), dataRow["PipeIn"].ToString(), dataRow["PipeOut"].ToString(), dataRow["PipeOverFlow"].ToString(), dataRow["PipeBlowOff"].ToString(), dataRow["Weight"].ToString()));
				}
			}
			return list;
		}

		public TreeView GetAllFamilyTreeList(string tableName)
		{
			TreeView treeView = new TreeView();
			DataTable allNameAndParentId = this.sqlHelper.GetAllNameAndParentId(tableName);
			if (allNameAndParentId != null && allNameAndParentId.Rows.Count > 0)
			{
				foreach (object obj in allNameAndParentId.Rows)
				{
					DataRow dataRow = (DataRow)obj;
					if (dataRow["ParentId"].ToString() == "0")
					{
						TreeNode treeNode = new TreeNode(dataRow["Name"].ToString());
						treeNode.Tag = dataRow["id"].ToString();
						treeNode.Name = dataRow["ParentId"].ToString();
						treeView.Nodes.Add(treeNode);
					}
				}
				foreach (object obj2 in treeView.Nodes)
				{
					TreeNode treeNode2 = (TreeNode)obj2;
					foreach (object obj3 in allNameAndParentId.Rows)
					{
						DataRow dataRow2 = (DataRow)obj3;
						if (treeNode2.Tag.ToString() == dataRow2["ParentId"].ToString() && dataRow2["Family"] != null && dataRow2["Family"].ToString() != "")
						{
							TreeNode treeNode3 = new TreeNode(dataRow2["Name"].ToString());
							treeNode3.Tag = dataRow2["id"].ToString();
							treeNode3.Name = dataRow2["ParentId"].ToString();
							treeNode2.Nodes.Add(treeNode3);
						}
					}
				}
			}
			return treeView;
		}

		public List<ListItem> GetFamilyInfoByParentId(string tableName, int parentId)
		{
			List<ListItem> list = new List<ListItem>();
			DataTable infoByParentId = this.sqlHelper.GetInfoByParentId(tableName, parentId);
			if (infoByParentId != null && infoByParentId.Rows.Count > 0)
			{
				foreach (object obj in infoByParentId.Rows)
				{
					DataRow dataRow = (DataRow)obj;
					list.Add(new ListItem(dataRow["Name"].ToString(), dataRow["id"].ToString(), dataRow["ParentId"].ToString()));
				}
			}
			return list;
		}

		private SQLiteDataBaseHelper sqlHelper;
	}
}
